package com.dlry.serviceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dlry.db.TravelRequestRepository;
import com.dlry.entity.DlTravelRequest;

@Service
@Transactional
public class TravelServiceImpl implements TravelService {
	@Autowired
	private TravelRequestRepository travelRequestRepository;

	public void save(DlTravelRequest travel) {
		travelRequestRepository.save(travel);
	}

	public void delete(Long tId) {
		travelRequestRepository.delete(tId);
	}

	public DlTravelRequest findOne(Long tId) {
		return travelRequestRepository.findOne(tId);
	}

	public Page<DlTravelRequest> findAll(Integer page, Integer row) {
		Sort sort = new Sort(Direction.DESC, "createDate");
		Pageable pageable = new PageRequest(page, row, sort);
		return travelRequestRepository.findAll(pageable);
	}

}
